Repository navigation
fix(pdf): preserve document metadata when rebuilding an uploaded PDF - #2341
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
Keywords, title, author and other document information were lost as soon as a PDF was uploaded. The upload form always builds the stored file with PDFDocument.create() and copyPages(), even for a single file, and that only carries over the pages. Reordering pages drops the metadata in the same way. Later steps, including flattening and signing, keep the metadata, so the signed PDF came back with these fields blank. Add copyPdfMetadata, which copies the information dictionary to the new document, including custom entries. Use it when reordering pages, and in a new mergePdfBuffers helper that replaces the inline merge in the upload form. A merged document keeps the metadata of the first file, matching how the form already derives the document title from the first file. Add vitest coverage and a "test" script, using the vitest dev dependency that is already declared. Fixes OpenSignLabs#2140
|
@officialasishkumar is attempting to deploy a commit to the prafull 's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2140
Problem
A PDF signed through OpenSign comes back with its document information blank: keywords, title, author, subject and so on.
The loss happens at upload rather than at signing.
Form.jsxalways builds the stored file withPDFDocument.create()andcopyPages(), even for a single file, and that only carries over the pages.reorderPdfPagesrebuilds the document the same way. The later steps (flattenPdf,processPdf, the signature placeholder) load and save the existing document, so they keep the metadata.Fix
copyPdfMetadata(sourceDoc, targetDoc)copies the information dictionary to the rebuilt document, including custom entries and values stored as indirect objects.mergePdfBuffers(pdfBuffers)replaces the inline merge inForm.jsx, which also makes that path testable.reorderPdfPagesnow callscopyPdfMetadata.Behaviour to review
/MetadataXMP stream isn't copied. It can make claims such as PDF/A conformance that may no longer hold for a rebuilt file. The issue is about the document information fields, so I left this out.Tests
The frontend has
vitestas a dev dependency but no test script, so I added"test": "vitest run"andsrc/utils/pdfDocumentUtils.test.js. It covers:reorderPdfPages, including the resulting page orderWith the copy disabled, 6 of the 8 tests fail. The other two (no metadata, encrypted source) don't depend on the copy.
Manual verification
I ran a PDF with keywords and a title through
mergePdfBuffers,reorderPdfPages, the server'sflattenPdf, theprocessPdfsteps (form flatten and placeholder) andSignPdf. This used a script calling those functions directly, not the browser UI or the running server.vite buildalso succeeds.